#ifndef OPERATION_H__
#define OPERATION_H__

//include header
#include <covariant>

//using namespace
using namespace std;


namespace npSimpleFactory
{
    //class forward declaration
    
    class Operation ://  public BaseClass
        public covariant
    {
        //friend
        
        //embedded type
        
        //class skeleton
        public: Operation();
        public: Operation(const Operation& cpy);
        public: Operation(Operation&& mov) noexcept;
        public: virtual ~Operation();
        public: Operation& operator=(const Operation& asn);
        public: Operation& operator=(Operation&& mva) noexcept;
        public: virtual shared_ptr<covariant> clone() const throw();
        public: virtual shared_ptr<covariant> steal(void* sft=nullptr) throw();

        //other constructors
        
        //public methods
        public: virtual int getResult() const throw() = 0;
        public: void setNums(int firstNum, int secondNum) throw();
        
        //protected methods
        protected: int getFirstNum() const throw();
        protected: void setFirstNum(int firstNum) throw();
        protected: int getSecondNum() const throw();
        protected: void setSecondNum(int firstNum) throw();
        
        //private methods
        
        //protected data
        /* 类中不应该存在protected 访问级别的data
         * 要么私有，要么私有而后给出protected 访问级别的methods !!! */
        
        //private data
        /* 类中不应存在指针类型成员，
         * 取而代之，应使用智能指针予以包裹
         * 使用shared_ptr表示类拥有指针指向对象
         * 使用weak_ptr表示类仅可以使用指针指向对象
         * 智能指针对指针成员的封装和使用准则：
         * 1.类对象不允许使用unique_ptr包裹
         * 2.推敲业务逻辑，如果是共享的(share_ptr)，则尽可能少的共享指针对象
         * 3.如果从业务逻辑中发现类仅仅使用某个指针所指对象，则务必使用weak_ptr包裹指针，
         *   以此切实地描述这种使用而不拥有的关系
         * 4.类成员weak_ptr<*> ths，由其产生的，包裹this指针的，shared_ptr只允许在局部使用 */
        private: int firstNum;
        private: int secondNum;
        
        //static part
        
        //others
    };

    //inline functions
    inline Operation::Operation() // : BaseClass()
    {
        this->firstNum = 0;
        this->secondNum = 0;
    }
    
    inline Operation::Operation(const Operation& cpy) // : BaseClass(cpy)
    {
        this->firstNum = cpy.firstNum;
        this->secondNum = cpy.secondNum;
    }
    
    inline Operation::Operation(Operation&& mov) noexcept // : BaseClass(move(mov))
    {
        this->firstNum = mov.firstNum;
        this->secondNum = mov.secondNum;
    }
    
    inline Operation::~Operation()
    {
        
    }
    
    inline Operation& Operation::operator=(const Operation& asn)
    {
        if (this == &asn)
        {
            return *this;
        }
        else
        {
            // BaseClass::operator=(asn);
            
            //To do
            this->firstNum = asn.firstNum;
            this->secondNum = asn.secondNum;
            
            return *this;
        }
    }
    
    inline Operation& Operation::operator=(Operation&& mva) noexcept
    {
        if (this == &mva)
        {
            return *this;
        }
        else
        {
            // BaseClass::operator=(move(mva));
            
            //To do
            this->firstNum = mva.firstNum;
            this->secondNum = mva.secondNum;
            
            return *this;
        }
    }
    
    inline shared_ptr<covariant> Operation::clone() const throw()
    {
        //new an instance if not abstract.
        return shared_ptr<covariant>(); //shared_ptr<Operation>(new Operation(*this));
    }
    
    inline shared_ptr<covariant> Operation::steal(void* sft) throw()
    {
        Operation* shf = static_cast<Operation*>(sft);
        if (this == shf)
        {
            return shared_ptr<covariant>();
        }
        else
        {
            shared_ptr<Operation> ret;
            if (!shf)
            {
                //new an instance if not abstract.
                // ret = shared_ptr<Operation>(new Operation(*this));
                // shf = ret.get();
            }
            
            // BaseClass::steal(shf);
            
            //To do
            shf->firstNum = this->firstNum;
            shf->secondNum = this->secondNum;
            
            return ret;
        }
    }

    inline void Operation::setNums(int firstNum, int secondNum) throw()
    {
        this->firstNum = firstNum;
        this->secondNum = secondNum;
    }

    inline int Operation::getFirstNum() const throw()
    {
        return this->firstNum;
    }

    inline void Operation::setFirstNum(int firstNum) throw()
    {
        this->firstNum = firstNum;
    }

    inline int Operation::getSecondNum() const throw()
    {
        return this->secondNum;
    }

    inline void Operation::setSecondNum(int secondNum) throw()
    {
        this->secondNum = secondNum;
    }
} // namespace npSimpleFactory


#endif //OPERATION_H__
